<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>登录</title>
    <link href="../css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<!--登录-->
<!--账号：<input type="text" id="username"><br>-->
<!--密码：<input type="password" id="password"><br>-->
<!--<input type="button" id="submit" value="登录" onclick="login()"><br>-->


<div class="container">
    <form class="form-horizontal" style="width: 400px; margin: 100px auto" action="/loginsubmit" method="post">
        <div class="form-group">
            <label for="username" class="col-sm-2 control-label">账号</label>
            <div class="col-sm-10">
                <input type="text" class="form-control" name="username" id="username" placeholder="账号">
            </div>
        </div>
        <div class="form-group">
            <label for="password" class="col-sm-2 control-label">密码</label>
            <div class="col-sm-10">
                <input type="password" class="form-control" name="password" id="password" placeholder="密码">
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <a href="/visterlogin">游客登录</a>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <button type="button" class="btn btn-default" id="loginBtn" onclick="login()">登录</button>
                <button type="button" class="btn btn-default" id="registerBtn" onclick="register()">注册</button>
            </div>
        </div>
    </form>
</div>



<script src="../js/jquery-3.2.1.js"></script>
<script>

    function login() {
        $.ajax({
            url: "/userlogin",
            data: {
                username: $("#username").val(),
                password: $("#password").val()
            },
            success: function (result) {
                if (result.msg === "成功") {
                    window.location.href = "/"
                } else {
                    alert("账号密码错误")
                }
            }
        })
    }

    function register() {
        window.location.href = "/registerpage";
    }

</script>
</body>
</html>